package com.example.controllor;

import com.example.common.Result;
import com.example.entity.Shouhuodizhi;
import com.example.service.ShouhuodizhiService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shouhuodizhi")
public class ShouhuodizhiControllor {

    @Resource
    ShouhuodizhiService shouhuodizhiService;
    @PostMapping("/add")
    public Result add(@RequestBody Shouhuodizhi shouhuodizhi){
        shouhuodizhiService.add(shouhuodizhi);
        return Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        shouhuodizhiService.delete(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Shouhuodizhi shouhuodizhi){
        shouhuodizhiService.update(shouhuodizhi);
        return Result.success();
    }

    @GetMapping("/selectAll")
    public Result selectAll(Shouhuodizhi shouhuodizhi){
        List<Shouhuodizhi> shouhuodizhiList = shouhuodizhiService.selectAll(shouhuodizhi);
        return Result.success(shouhuodizhiList);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Shouhuodizhi shouhuodizhi){
        PageInfo<Shouhuodizhi> pageInfo = shouhuodizhiService.selectPage(pageNum, pageSize, shouhuodizhi);
        return Result.success(pageInfo);
    }
}
